package theOrbalEra.common.item;

import java.util.List;

import theOrbalEra.common.util.DefultValue;
import theOrbalEra.common.util.GetName;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;


public class OrbalItemQuartz extends OrbalItem {
	 private Icon[] loop;

	public OrbalItemQuartz(int par1) {
		super(par1);
		this.setMaxStackSize(1);
		
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack par1ItemStack,EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
		if(par1ItemStack!=null){
			int ele=OrbalItemQuartz.getEle(par1ItemStack);
			int able=OrbalItemQuartz.getAble(par1ItemStack);
			if(able!=-1)
			par3List.add(GetName.localize("quartz.".concat(GetName.getQuartzName(able))));
			else
				par3List.add(GetName.localize("display.none"));
			
			if(ele!=-1)
				par3List.add(GetName.localize(GetName.EleName(ele)));
			else
				par3List.add(GetName.localize("display.none"));
			}
		super.addInformation(par1ItemStack, par2EntityPlayer, par3List, par4);
		
		
	}

	public static int getAble(ItemStack par1ItemStack) {
		NBTTagCompound var1= par1ItemStack.getTagCompound();
		if(var1==null){
			return -1;
		}
		else{
			NBTTagCompound var2=var1.getCompoundTag("quartz");
			return var2==null?-1:(var2.hasKey("quartz")?var2.getInteger("quartz"):-1);
		}
		
	}
	 public static int getEle(ItemStack par1ItemStack) {
		NBTTagCompound var1= par1ItemStack.getTagCompound();
		if(var1==null){
			return -1;
		}
		else{
			NBTTagCompound var2=var1.getCompoundTag("quartz");
			return var2==null?-1:(var2.hasKey("ele")?var2.getInteger("ele"):-1);
		}
		
	}
	 public static void setAble(ItemStack par1ItemStack, int par2){
		 NBTTagCompound var1 = par1ItemStack.getTagCompound();

	        if (var1 == null)
	        {
	            var1 = new NBTTagCompound();
	            par1ItemStack.setTagCompound(var1);
	        }

	        NBTTagCompound var2 = var1.getCompoundTag("quartz");

	        if (!var1.hasKey("quartz"))
	        {
	            var1.setCompoundTag("quartz", var2);
	        }

	        if (par2 != -1)
	        {
	            var2.setInteger("quartz", par2);
	        }
	        else
	        {
	            var2.removeTag("quartz");
	        }
	 }
	 public static void setEle(ItemStack par1ItemStack, int par2){
		 NBTTagCompound var1 = par1ItemStack.getTagCompound();

	        if (var1 == null)
	        {
	            var1 = new NBTTagCompound();
	            par1ItemStack.setTagCompound(var1);
	        }

	        NBTTagCompound var2 = var1.getCompoundTag("quartz");

	        if (!var1.hasKey("quartz"))
	        {
	            var1.setCompoundTag("quartz", var2);
	        }

	        if (par2 != -1)
	        {
	            var2.setInteger("ele", par2);
	        }
	        else
	        {
	            var2.removeTag("ele");
	        }
	 }
	 
	 @Override
	@SideOnly(Side.CLIENT)
	public Icon getIconFromDamage(int par1) {
		 if (par1 < 0 || par1 > 7)
	        {
	            par1 = 7;
	        }

	        return this.loop[par1];
	}
	 @Override
		@SideOnly(Side.CLIENT)
		public void registerIcons(IconRegister par1IconRegister) {
		 this.loop=new Icon[7];
	        for (int i = 0; i < this.loop.length; ++i)
	        {
	            this.loop[i] = par1IconRegister.registerIcon(DefultValue.ModName+":quartz_" + i);
	        }
	}

	

	

}
